/*
 * Copyright 2006-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.martinimix.domain.order;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Calendar;

/**
 * Provides an order header bean.
 * 
 * @author Scott Rossillo
 *
 */
public class OrderHeader implements Serializable {
	
	public final static String STATUS_NEW = "N";
	public final static String STATUS_PAYMENT_SUCCEEDED = "M";
	public final static String STATUS_PENDING_AUTHORIZATION = "A";
	public final static String STATUS_REJECTED = "J";
	public final static String STATUS_SUBMITTED = "S";
	
	private static final long serialVersionUID = 1L;
	
	/**
	 * @@BusinessObjectProperty("orh_id") 
	 */
	private Long id;
	
	/**
	 * @@BusinessObjectProperty("orderNum") 
	 */
	private String orderNumber;
	
	/**
	 * @@BusinessObjectProperty("ext_so_nbr") 
	 */
	private String externalOrderNumber;
	
	
	/**
	 * @@BusinessObjectProperty("orh_uad_id")
	 */
	private Long billToId;
	
	/**
	 * @@BusinessObjectProperty("createdFor") 
	 */
	private Long createdForCustomerId;
	
	/**
	 * @@BusinessObjectProperty("createdFor") 
	 */
	private Long priceListFolderId;
	
	/**
	 * @@BusinessObjectProperty("currency_cd") 
	 */
	private String currencyCode;
	
	/**
	 * @@BusinessObjectProperty("type_cd") 
	 */
	private String typeCode;
	
	/**
	 * @@BusinessObjectProperty("status_cd") 
	 */
	private String statusCode;
	
	/**
	 * @@BusinessObjectProperty("source_cd") 
	 */
	private String sourceCode;
	
	/**
	 * @@BusinessObjectProperty("subtotalAmt") 
	 */
	private BigDecimal subTotalPrice;
	
	private BigDecimal taxableAmount;
	
	/**
	 * @@BusinessObjectProperty("totalAmt") 
	 */
	private BigDecimal totalPrice;
	
	/**
	 * @@BusinessObjectProperty("discountAmt") 
	 */
	private BigDecimal discountAmount;
	
	/**
	 * @@BusinessObjectProperty("totalTaxAmt") 
	 */
	private BigDecimal taxAmount;
	
	/**
	 * @@BusinessObjectProperty("totalShipAmt") 
	 */
	private BigDecimal shipAmount;
	
	private boolean ignoreSequence;
	
	private Long shipMethodId;
	
	/**
	 * @@BusinessObjectProperty("createDt")
	 */
	private Calendar createdDate;
	
	/**
	 * @@BusinessObjectProperty("modifyDt")
	 */
	private Calendar modifiedDate;
	
	/**
	 * @@BusinessObjectProperty("ClientIPAddress", attribute=true) 
	 */
	private String ipAddress;
	
	/**
	 * hack to make bm not puke/barf when creating a new orders
	 * 
	 * @@BusinessObjectProperty("new") 
	 */
	private boolean newOrder;
	
	private Long createdBy;
	private Long modifiedBy;
	
	/**
	 * Creates a new order header.
	 */
	public OrderHeader() {
		
		subTotalPrice = BigDecimal.valueOf(0L, 2);
		totalPrice = BigDecimal.valueOf(0L, 2);
		discountAmount = BigDecimal.valueOf(0L, 2);
		
		taxAmount = BigDecimal.valueOf(0L, 2);
		shipAmount = BigDecimal.valueOf(0L, 2);
		
		currencyCode = "USD";
		typeCode = "ORD";
	}
	
	/**
	 * Creates a copy of the given order header.
	 * 
	 * @param orderHeader the <code>OrderHeader</code> to copy
	 */
	public OrderHeader(OrderHeader orderHeader) {
		
		this.id = orderHeader.id;
		
		this.billToId = orderHeader.billToId;
		this.createdForCustomerId = orderHeader.createdForCustomerId;
		
		this.externalOrderNumber = orderHeader.externalOrderNumber;
		this.ignoreSequence = orderHeader.ignoreSequence;
		this.newOrder = orderHeader.newOrder;
		
		this.orderNumber = orderHeader.orderNumber;
		this.priceListFolderId = orderHeader.priceListFolderId;
		
		this.shipAmount = orderHeader.shipAmount;
		this.shipMethodId = orderHeader.shipMethodId;
		
		
		this.sourceCode = orderHeader.sourceCode;
		this.statusCode = orderHeader.statusCode;
		this.typeCode = orderHeader.typeCode;
		this.currencyCode = orderHeader.currencyCode;
		
		this.discountAmount = orderHeader.discountAmount;
		this.subTotalPrice = orderHeader.subTotalPrice;
		this.taxAmount = orderHeader.taxAmount;
		this.totalPrice = orderHeader.totalPrice;
		
		this.ipAddress = orderHeader.ipAddress;
		
		this.createdBy = orderHeader.createdBy;
		this.modifiedBy = orderHeader.modifiedBy;
		
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getOrderNumber() {
		return orderNumber;
	}

	public void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}

	public String getExternalOrderNumber() {
		return externalOrderNumber;
	}

	public void setExternalOrderNumber(String externalOrderNumber) {
		this.externalOrderNumber = externalOrderNumber;
	}

	/**
	 * Returns the bill to address identifier for this order.
	 * 
	 * @return the bill to <code>Address</code> id for this order
	 */
	public Long getBillToId() {
		return billToId;
	}

	/**
	 * Sets the bill to address identifier for this order.
	 * 
	 * @param billToId the <code>Address</code> identifier where this
	 * <code>OrderHeader</code> will be billed to
	 */
	public void setBillToId(Long billToId) {
		this.billToId = billToId;
	}

	public Long getCreatedForCustomerId() {
		return createdForCustomerId;
	}
	public void setCreatedForCustomerId(Long createdForCustomerId) {
		this.createdForCustomerId = createdForCustomerId;
	}
	public Long getPriceListFolderId() {
		return priceListFolderId;
	}
	public void setPriceListFolderId(Long priceListFolderId) {
		this.priceListFolderId = priceListFolderId;
	}
	public String getCurrencyCode() {
		return currencyCode;
	}
	public void setCurrencyCode(String currencyCode) {
		this.currencyCode = currencyCode;
	}
	public Long getShipMethodId() {
		return shipMethodId;
	}

	public void setShipMethodId(Long shipMethodId) {
		this.shipMethodId = shipMethodId;
	}

	public String getTypeCode() {
		return typeCode;
	}
	public void setTypeCode(String typeCode) {
		this.typeCode = typeCode;
	}
	public String getStatusCode() {
		return statusCode;
	}
	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}
	public String getSourceCode() {
		return sourceCode;
	}
	public void setSourceCode(String sourceCode) {
		this.sourceCode = sourceCode;
	}
	public BigDecimal getSubTotalPrice() {
		return subTotalPrice;
	}
	public void setSubTotalPrice(BigDecimal subTotalPrice) {
		this.subTotalPrice = subTotalPrice;
	}
	public BigDecimal getTotalPrice() {
		return totalPrice;
	}
	public void setTotalPrice(BigDecimal totalPrice) {
		this.totalPrice = totalPrice;
	}
	public BigDecimal getDiscountAmount() {
		return discountAmount;
	}
	public void setDiscountAmount(BigDecimal discountAmount) {
		this.discountAmount = discountAmount;
	}

	public boolean isIgnoreSequence() {
		return ignoreSequence;
	}

	public void setIgnoreSequence(boolean ignoreSequence) {
		this.ignoreSequence = ignoreSequence;
	}

	public boolean isNewOrder() {
		return newOrder;
	}

	public void setNewOrder(boolean newOrder) {
		this.newOrder = newOrder;
	}

	public String getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}

	public BigDecimal getTaxAmount() {
		return taxAmount;
	}

	public void setTaxAmount(BigDecimal taxAmount) {
		this.taxAmount = taxAmount;
	}

	public BigDecimal getShipAmount() {
		return shipAmount;
	}

	public void setShipAmount(BigDecimal shipAmount) {
		this.shipAmount = shipAmount;
	}

	public Long getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(Long createdBy) {
		this.createdBy = createdBy;
	}

	public Long getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(Long modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	public Calendar getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Calendar createdDate) {
		this.createdDate = createdDate;
	}

	public Calendar getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Calendar modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	/**
	 * Returns the sub-total amount of this order that is taxable.
	 * 
	 * @return a <code>BigDecimal</code> containing the taxable
	 * amount of this order if set; <code>null</code> otherwise
	 */
	public BigDecimal getTaxableAmount() {
		return taxableAmount;
	}

	/**
	 * Sets the amount of this order's sub-total that's taxable.
	 * 
	 * @param taxableAmount the taxable amount of this order
	 */
	public void setTaxableAmount(BigDecimal taxableAmount) {
		this.taxableAmount = taxableAmount;
	}


}
